home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 1998 June / SGI IRIX 6.5 Applications 1998 June.iso / dist / arraysvcs.idb / usr / lib / array / atopm.z / atopm
Text File  |  1998-04-15  |  2KB  |  81 lines

  1. #!/usr/bin/perl
  2. #
  3. # Simple script to implement "array top". 
  4. #
  5. # Usage: atop local <name>
  6. #    or: atop merge <file....>
  7. #
  8.  
  9. #
  10. # The local variant: this should be run on each node in the array
  11. #
  12. if ($ARGV[0] eq "local") {
  13.  
  14.     #
  15.     # Start up a "top" command and trap its output
  16.     #
  17.     open(ATOP, "/usr/sbin/atop -f 2 |") || die "Couldn't run atop: $!\n";
  18.  
  19.     #
  20.     # Process each line of atop output
  21.     #
  22.     while (<ATOP>) {
  23.  
  24.     #
  25.     # Split out individual fields
  26.     #
  27.     ($user, $pid, $ash, $cpu, $cmd) = split(" ", $_);
  28.  
  29.     #
  30.     # Print the results neatly, tossing ASH "0" (which is normally
  31.     # just system processes)
  32.     #
  33.     printf "0x%16s %-12s %5s %-8.8s %6s %s\n",
  34.         $ash, $ARGV[1], $pid, $user, $cpu, $cmd
  35.             unless $ash eq "0000000000000000"
  36.     }
  37. }
  38.  
  39. #
  40. # The merge variant: this is run only on one node using the output
  41. # from "aps local" on each node as its input files
  42. #
  43. elsif ($ARGV[0] eq "merge") {
  44.  
  45.     #
  46.     # Read all of the input files into a list
  47.     #
  48.     shift @ARGV;
  49.     @all = <ARGV>;
  50.  
  51.     #
  52.     # Sort the list using the "sorttop" subroutine
  53.     #
  54.     @new = sort sorttop @all;
  55.  
  56.     #
  57.     # Print a nice header line
  58.     #
  59.     print "        ASH        Host           PID User       %CPU Command\n";
  60.     print "----------------------------------------------------------------\n";
  61.  
  62.     #
  63.     # Print every line
  64.     #
  65.     foreach $line (@new) {
  66.     print $line
  67.     }
  68. }
  69.  
  70.  
  71.  
  72. #
  73. # Sort function: sorts "atop local" lines first by CPU then by user
  74. #
  75. sub sorttop {
  76.     ($Aash, $Ahost, $Apid, $Auser, $Acpu, $Acmd) = split(" ", $a);
  77.     ($Bash, $Bhost, $Bpid, $Buser, $Bcpu, $Bcmd) = split(" ", $b);
  78.  
  79.     (($Bcpu <=> $Acpu) || ($Buser cmp $Auser));
  80. }
  81.